﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using InternalManagementSystem.DAO.Models;
using System.Web.Configuration;
using System.Configuration;

public partial class Companys_Create : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        PermissionHelper hh = new PermissionHelper();
        Session["Permission"] = hh.GetPermission(EUserRole.superadmin);

        btnCreate.Visible = false;
        

        if (Session["Permission"] != null)
        {
            Permission permission = Session["Permission"] as Permission;
            if (permission.IsCompanyEdit)
            {
                btnCreate.Visible = true;
                txtGuardLine.Text = "6";
                txtCurrentIntegral.Text = "12";
            }
             
        }
        
        txtxStatisticalStartDate.Text = DateTime.Now.ToString("yyyy-MM-dd");
    }

    protected void btnCreate_Click(object sender, EventArgs e)
    {
        if (Session["Permission"] != null)
        {
            Permission permission = Session["Permission"] as Permission;

           
            if (permission != null )
            {
                Company company = new Company();
                company.Address = txtAddress.Text;
                company.CompanyName = txtCompanyName.Text;
                company.Contact = txtContact.Text;
                company.ContactPerson = txtContactPerson.Text;
                company.CurrentIntegral =Convert.ToInt32( txtCurrentIntegral.Text);
                company.Email = txtEmail.Text;
                company.Phone = txtPhone.Text;
                company.GuardLine = Convert.ToInt32(txtGuardLine.Text);
                if ( rbAutoRecharge.Checked)
                {
                    company.IsAutoRecharge = 1;
                }

                if (rbUnAutoRecharge.Checked)
                {
                    company.IsAutoRecharge = 0;
                }

                
                company.StatisticalStartDate = Convert.ToDateTime(txtxStatisticalStartDate.Text);
                
                CompanyBLL cbll = new CompanyBLL(permission);
                
                cbll.AddCompany(company);

                Response.Write("<script> alert( '提交成功！ ');location= 'Index.aspx'</script> ");
            
            }
        }
    }

    protected void btnReturn_Click(object sender, EventArgs e)
    {
        Response.Redirect("Index.aspx");
    }
}
